{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-10-27T09:31:58.058523Z",
     "start_time": "2025-10-27T09:31:58.004089Z"
    }
   },
   "source": [
    "import sqlalchemy\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from sqlalchemy import create_engine\n",
    "import pymysql\n",
    "print(sqlalchemy.__version__)\n",
    "print(pymysql.__version__)\n",
    "pymysql.install_as_MySQLdb()\n",
    "df=pd.DataFrame({\"班级\":[\"一年级\",\"二年级\",\"s\"],\n",
    "                 \"fff\":[1,2,3]})\n",
    "engine=create_engine('mysql+pymysql://root:123456@127.0.0.1:3306/student_management?charset=utf8mb4')\n",
    "df.to_sql('student',engine,if_exists='append',index=False)\n",
    "print(df)\n",
    "\n",
    "print(pd.read_sql('scores',engine))"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.0.39\n",
      "1.4.6\n",
      "    班级  fff\n",
      "0  一年级    1\n",
      "1  二年级    2\n",
      "2    s    3\n",
      "Empty DataFrame\n",
      "Columns: [score_id, student_id, course_id, score, exam_date, remark, create_time]\n",
      "Index: []\n"
     ]
    }
   ],
   "execution_count": 34
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-27T09:30:10.300942Z",
     "start_time": "2025-10-27T09:30:10.288347Z"
    }
   },
   "cell_type": "code",
   "source": [
    "data = np.arange(12).reshape((3,4))\n",
    "df3 = pd.DataFrame(data,index=['d','b','c'],columns=['dd','aa','cc','bb'])\n",
    "print(df3)\n",
    "df3.sort_index(axis=0)  #行排序\n",
    "print(df3)\n",
    "df3.sort_index(axis=1)  #列排序\n",
    "print(df3)\n",
    "df3.sort_values(by='cc')  #按’cc’列的数据进行排序\n",
    "print(df3)"
   ],
   "id": "1d166b5beed10799",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   dd  aa  cc  bb\n",
      "d   0   1   2   3\n",
      "b   4   5   6   7\n",
      "c   8   9  10  11\n",
      "   dd  aa  cc  bb\n",
      "d   0   1   2   3\n",
      "b   4   5   6   7\n",
      "c   8   9  10  11\n",
      "   dd  aa  cc  bb\n",
      "d   0   1   2   3\n",
      "b   4   5   6   7\n",
      "c   8   9  10  11\n",
      "   dd  aa  cc  bb\n",
      "d   0   1   2   3\n",
      "b   4   5   6   7\n",
      "c   8   9  10  11\n"
     ]
    }
   ],
   "execution_count": 31
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
